/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.*

/**
 * Groups
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface GroupsApi {


    /**
     * List groups
     */
    @GetMapping("/identity/groups")
    fun listGroups(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "name", required = false) name: String?,
        @RequestParam(name = "type", required = false) type: String?,
        @RequestParam(name = "nameLike", required = false) nameLike: String?,
        @RequestParam(name = "member", required = false) member: String?,
        @RequestParam(name = "potentialStarter", required = false) potentialStarter: String?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<GroupResponse>>

    /**
     * Create a group
     */
    @PostMapping("/identity/groups")
    fun createGroup(
        @RequestBody(required = false) body: GroupRequest?
    ): R<GroupResponse>

    /**
     * Get a single group
     */
    @GetMapping("/identity/groups/{groupId}")
    fun getGroup(
        @PathVariable("groupId") groupId: String
    ): R<GroupResponse>

    /**
     * All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only updating the name of the group, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the group-value will be updated to null.
     */
    @PutMapping("/identity/groups/{groupId}")
    fun updateGroup(
        @PathVariable("groupId") groupId: String,
        @RequestBody(required = false) body: GroupRequest?
    ): R<GroupResponse>

    /**
     * Delete a group
     */
    @DeleteMapping("/identity/groups/{groupId}")
    fun deleteGroup(
        @PathVariable("groupId") groupId: String
    ): R<Any>

    /**
     * Add a member to a group
     */
    @PostMapping("/identity/groups/{groupId}/members")
    fun createMembership(
        @PathVariable("groupId") groupId: String,
        @RequestBody(required = false) body: MembershipRequest?
    ): R<MembershipResponse>

    /**
     * Delete a member from a group
     */
    @DeleteMapping("/identity/groups/{groupId}/members/{userId}")
    fun deleteMembership(
        @PathVariable("groupId") groupId: String,
        @PathVariable("userId") userId: String
    ): R<Any>
}